import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import scoreatpercentile
from scipy import stats
import scipy as sp

def build_data_list(inputCSV):
    sKey = []
    fn = inputCSV
    ra = csv.DictReader(file(fn), dialect="excel")
    
    for record in ra:
        #print record[ra.fieldnames[0]], type(record[ra.fieldnames[-1]])
        for item in ra.fieldnames:
            temp = float(record[item])
            sKey.append(temp)
    sKey = np.array(sKey)
    sKey.shape=(-1,len(ra.fieldnames))
    return sKey


#--------------------------------------------------------------------------
#MAIN

if __name__ == "__main__":
    inputCSV = 'C:/Documents and Settings/wang322/My Documents/My Dropbox/STAT704/Final/output.csv'
    data = build_data_list(inputCSV)
    fig = plt.figure()
    ax1 = fig.add_subplot(221)
    ax1.scatter(data[:,0], data[:,8], marker = 'x')
    #ax.scatter(extraData[:,1], extraData[:,0])
    ax1.set_xlabel('Case')
    ax1.set_ylabel('Studentized Deleted Residual')
    ax1.set_xlim([-5, 140])
    #ax.set_ylim([-10, 170])
    
    ax1.plot([-5, 140], [3.66204, 3.66204], '--')
    ax1.plot([-5, 140], [-3.66204, -3.66204], '--')

    ax2 = fig.add_subplot(222)
    ax2.scatter(data[:,0], data[:,9], marker = 'x')
    #ax.scatter(extraData[:,1], extraData[:,0])
    ax2.set_xlabel('Case')
    ax2.set_ylabel('Hat Diag H')
    ax2.set_xlim([-5, 140])
    ax2.plot([-5, 140], [0.0606, 0.0606], '--')

    ax3 = fig.add_subplot(223)
    ax3.scatter(data[:,0], data[:,7], marker = 'x')
    ax3.set_xlabel('Case')
    ax3.set_ylabel("Cook's D")
    ax3.set_xlim([-5, 140])
    ax3.plot([-5, 140], [0.028, 0.028], '--')

    ax4 = fig.add_subplot(224)
    ax4.scatter(data[:,0], data[:,11], marker = 'x')
    ax4.set_xlabel('Case')
    ax4.set_ylabel("DFFITS")
    ax4.set_xlim([-5, 140])
    ax4.plot([-5, 140], [0.3481553119113957, 0.3481553119113957], '--')


    plt.show()
    